package com.java.test.system.gametypemanage;


import com.java.test.controller.BaseController;
import com.java.test.dto.PageResultDTO;
import com.java.test.dto.ResponseDTO;
import com.java.test.system.dto.LoginAccountInfo;
import com.java.test.system.gametypemanage.dto.GameTypeAddDTO;
import com.java.test.system.gametypemanage.dto.GameTypeDTO;
import com.java.test.system.gametypemanage.dto.GameTypeQueryDTO;
import com.java.test.system.gametypemanage.dto.GameTypeUpdateDTO;
import com.java.test.system.gametypemanage.entity.GameTypeEntity;
import org.springframework.web.bind.annotation.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.Date;

/**
 * 游戏类型管理
 * @author lijie1
 */
@Slf4j
@RestController
@RequestMapping("/systemConfig/gameTypeManage")
public class GameTypeManageController extends BaseController {
    @Autowired
    GameTypeManageService gameTypeManageService;

    /**
     * 游戏类型查询
     * @return
     */
    @RequestMapping(value = "/selectToList",method = RequestMethod.POST)
    public ResponseDTO<PageResultDTO<GameTypeEntity>> gameTypeList(@RequestBody @Valid GameTypeQueryDTO queryDTO) {
        log.info("----------进入游戏类型查询----------");
        return gameTypeManageService.getGameTypeList(queryDTO);
    }

    /**
     * 游戏类型新增
     * @return
     */
    @RequestMapping(value = "/save",method = RequestMethod.POST)
    public ResponseDTO<String> addGameType(@RequestBody @Valid GameTypeAddDTO addDTO, HttpServletRequest request) {
        log.info("----------进入游戏类型添加----------");
        addDTO.setStatus(1);
        addDTO.setCreateTime(new Date());
        LoginAccountInfo user = (LoginAccountInfo) request.getSession().getAttribute("user");
        systemManageService.insertlogInfo(user.getLoginAccout(), user.getIp(), "系统管理-游戏类型管理-游戏类型添加");
        addDTO.setOperation(user.getLoginAccout());
        return gameTypeManageService.addGameType(addDTO);
    }

    /**
     * 通过id获取游戏类型
     * @param dto
     * @return
     */
    @RequestMapping(value = "/selectById",method = RequestMethod.POST)
    public ResponseDTO<GameTypeEntity> selectById(@RequestBody @Valid GameTypeDTO dto) {
        log.info("----------游戏类型查询----------");
        return gameTypeManageService.selectById(dto.getId());
    }

    /**
     * 修改游戏类型
     * @param updateDTO
     * @return
     */
    @RequestMapping(value = "/updateById",method = RequestMethod.POST)
    public ResponseDTO<String> updateGameType(@RequestBody @Valid GameTypeUpdateDTO updateDTO, HttpServletRequest request) {
        log.info("----------游戏类型修改----------");
        updateDTO.setModifyTime(new Date());
        LoginAccountInfo user = (LoginAccountInfo) request.getSession().getAttribute("user");
        systemManageService.insertlogInfo(user.getLoginAccout(), user.getIp(), "系统管理-游戏类型管理-游戏类型修改");
        updateDTO.setModify(user.getLoginAccout());
        return gameTypeManageService.updateGameType(updateDTO);
    }

    /**
     * 通过id删除游戏类型
     * @param dto
     * @return
     */
    @RequestMapping(value = "/deleteById",method = RequestMethod.POST)
    public ResponseDTO<String> deleteById(@RequestBody @Valid GameTypeDTO dto, HttpServletRequest request) {
        log.info("----------游戏类型删除----------");
        LoginAccountInfo user = (LoginAccountInfo) request.getSession().getAttribute("user");
        systemManageService.insertlogInfo(user.getLoginAccout(), user.getIp(), "系统管理-游戏类型管理-游戏类型删除");
        return gameTypeManageService.deleteById(dto.getId());
    }

}
